<?php
    //增加商品
    header("Access-Control-Allow-Origin: *"); // 允许跨域的地址，* 表示全部
    header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS"); // 允许的请求方法
    header("Access-Control-Allow-Headers: version, access-token, user-token"); // 允许的请求头属性
    header('content-type:text/html;charset=utf-8');
    
    include '../util/connect.php';

    $GoodsName = $_POST['GoodsName'];//商品名称
    $CapacityAndPrice = $_POST['CapacityAndPrice'];//存储容量和价格
    $icon = $_FILES['Image'];//图片
    $name = $icon['name']; //获取文件名
    $temp = $icon['tmp_name'];//获取临时路径
    $gbkname = iconv('utf-8','gbk',$name);
    move_uploaded_file($temp,'../../goodsimage/'.$gbkname); //移动到指定目录下
    $Image = 'http://47.107.172.64/zhitong_API/goodsimage/'.$name;
    //生成唯一GoodsId
    $GoodsId = uniqid('zt');
    date_default_timezone_set('PRC');
    $CreateTime = date("Y-m-d H:i:s");//上架时间


    $sql = "insert into goodstemp(GoodsId,GoodsName,Image,CapacityAndPrice,CreateTime) 
    values('$GoodsId','$GoodsName','$Image','$CapacityAndPrice','$CreateTime')";
    $result = my_ZSG($sql);
        if ($result) {
            $arr = [
                "status" => 0,
                "message" => "新增成功"
            ];
        }else{
            $arr = [
                "status" => 2,
                "message" => "新增失败"
            ];
        }
    echo json_encode($arr,JSON_UNESCAPED_UNICODE);